package com.officegameapp.db.implementation.hibernate;

import java.util.List;

import org.hibernate.Session;

import com.officegameapp.db.dao.IGameDAO;
import com.officegameapp.db.entities.Game;

public class GameDAO implements IGameDAO {

	@Override
	public void persist(Game g) {
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		session.saveOrUpdate(g);
		session.getTransaction().commit();
	}
	
	@Override
	public void create(Game g) {
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		session.save(g);
		session.getTransaction().commit();
	}

	@Override
	public List<Game> getGames() {
		Session session = HibernateUtil.getSession();
		List<Game> games = (List<Game>) session.createCriteria(Game.class).list();
		return games;
	}
}
